<?php if (!defined('THINK_PATH')) exit();?><style>
    .content {
        padding-left:15px;
    }
</style>
<input type="hidden" value="<?php echo ($data["id"]); ?>" id="id"/>
<div class="box box-warning">
    <div class="box-header with-border">
        <h3 class="box-title">
            <?php if(empty($data["id"])): ?>添加货币信息<?php else: ?>修改货币信息<?php endif; ?>
        </h3>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <form role="form">
            <!-- text input -->
            <div class="form-group" style="overflow:hidden;">
                <div style="width:100%"><label>货币名称/编码</label></div>
                <div style="float:left;display:block;width:49%">
                    <input id="game_name" type="text" name="game_name" value="<?php echo ($data["game_name"]); ?>" class="form-control" placeholder="货币名称">
                </div>
                <div style="float:left;width:2%;display:block;text-align:center;">-</div>
                <div style="float:left;display:block;width:49%">
                    <input id="name_code" type="text" name="name_code" value="<?php echo ($data["name_code"]); ?>" class="form-control" placeholder="货币编码">
                </div>
            </div>

            <div class="form-group" style="overflow:hidden;">
                <div style="width:100%"><label>汇率/倍率</label></div>
                <div style="float:left;display:block;width:49%">
                    <input id="exchange_rate" type="text" name="exchange_rate" value="<?php echo ($data["exchange_rate"]); ?>" class="form-control" placeholder="汇率">
                </div>
                <div style="float:left;width:2%;display:block;text-align:center;">-</div>
                <div style="float:left;display:block;width:49%">
                    <input id="multiplying_power" type="text" name="multiplying_power" value="<?php echo ($data["multiplying_power"]); ?>" class="form-control" placeholder="倍率">
                </div>
            </div>

            <div class="form-group" style="overflow:hidden;">
                <div style="width:100%"><label>显示名称/规格</label></div>
                <div style="float:left;display:block;width:49%">
                    <input id="show_name" type="text" name="show_name" value="<?php echo ($data["show_name"]); ?>" class="form-control" placeholder="显示名称">
                </div>
                <div style="float:left;width:2%;display:block;text-align:center;">-</div>
                <div style="float:left;display:block;width:49%">
                    <input id="norms" type="text" name="norms" value="<?php echo ($data["norms"]); ?>" class="form-control" placeholder="货币规格">
                </div>
            </div>

            <div class="form-group">
                <label>数值精确位数</label>
                <input id="value_length" type="text" name="value_length" value="<?php echo ($data["value_length"]); ?>" class="form-control" placeholder="数值精确小数位数">
            </div>
            <?php if(is_array($data["list_profit"])): $i = 0; $__LIST__ = $data["list_profit"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$profit): $mod = ($i % 2 );++$i;?><div class="form-group list_profit" style="overflow:hidden;">
                    <div style="width:100%"><label>触摸点位 - 收益率（%）</label><span> - <a href="javascript:void(0)" onclick="del_profit(this)">[删除]</a></span></div>
                    <div style="float:left;display:block;width:49%">
                        <input type="text" name="contact" value="<?php echo ($profit["contact"]); ?>" class="form-control" placeholder="触摸点位">
                    </div>
                    <div style="float:left;width:2%;display:block;text-align:center;">-</div>
                    <div style="float:left;display:block;width:49%">
                        <input type="text" name="profit_rate" value="<?php echo ($profit["profit_rate"]); ?>" class="form-control" placeholder="收益比例">
                    </div>
                </div><?php endforeach; endif; else: echo "" ;endif; ?>
            <div class="form-group">
                <a href="javascript:void(0)" onclick="add_profit(this)">+新增触摸点位</a>
            </div>

            <div class="form-group">
                <div style="width:100%"><label>交易时间</label></div>
                <div style="float:left;margin-right:10px;display:block;">
                    <div class="checkbox"> <label for="mon"><input type="checkbox" id="mon" name="mon" <?php echo ($data['mon']==1?'checked':''); ?>>周一</label></div>
                </div>
                <div style="float:left;margin-right:10px;display:block;">
                    <div class="checkbox"> <label for="tue"><input type="checkbox" id="tue" name="tue" <?php echo ($data['tue']==1?'checked':''); ?>>周二</label></div>
                </div>
                <div style="float:left;margin-right:10px;display:block;">
                    <div class="checkbox"> <label for="wed"><input type="checkbox" id="wed" name="wed" <?php echo ($data['wed']==1?'checked':''); ?>>周三</label></div>
                </div>
                <div style="float:left;margin-right:10px;display:block;">
                    <div class="checkbox"> <label for="thu"><input type="checkbox" id="thu" name="thu" <?php echo ($data['thu']==1?'checked':''); ?>>周四</label></div>
                </div>
                <div style="float:left;margin-right:10px;display:block;">
                    <div class="checkbox"> <label for="fri"><input type="checkbox" id="fri" name="fri" <?php echo ($data['fri']==1?'checked':''); ?>>周五</label></div>
                </div>
                <div style="float:left;margin-right:10px;display:block;">
                    <div class="checkbox"> <label for="sat"><input type="checkbox" id="sat" name="sat" <?php echo ($data['sat']==1?'checked':''); ?>>周六</label></div>
                </div>
                <div style="float:left;margin-right:10px;display:block;">
                    <div class="checkbox"> <label for="sun"><input type="checkbox" id="sun" name="sun" <?php echo ($data['sun']==1?'checked':''); ?>>周日</label></div>
                </div>
            </div>
            <div class="form-group">
                <div style="float:left;margin-right:10px;display:block;">
                    <div class="col-xs-3" style="padding-left:0px;">
                        <div class="bootstrap-timepicker">
                            <div class="form-group">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn bg-olive">每日</button>
                                    </div>
                                    <input type="text" id="open_time" name="open_time" value="<?php echo ((isset($data['open_time']) && ($data['open_time'] !== ""))?($data['open_time']):date('H:i')); ?>" class="form-control timepicker">

                                    <div class="input-group-addon">
                                        <i class="fa fa-clock-o"></i>
                                    </div>
                                </div>
                                <!-- /.input group -->
                            </div>
                            <!-- /.form group -->
                        </div>
                    </div>
                    <span style="float:left;line-height:30px;">至</span>
                    <div class="col-xs-3">
                        <div class="bootstrap-timepicker">
                            <div class="form-group">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <select name="close_time_type" id="close_time_type" class="form-control" style="width: auto;">
                                            <option value="1" <?php echo ($data['close_time_type']==1?'selected':''); ?>>当日</option>
                                            <option value="2" <?php echo ($data['close_time_type']==2?'selected':''); ?>>次日</option>
                                        </select>
                                    </div>

                                    <input type="text" id="close_time" name="close_time" value="<?php echo ((isset($data['close_time']) && ($data['close_time'] !== ""))?($data['close_time']):date('H:i')); ?>" class="form-control timepicker">
                                    <div class="input-group-addon">
                                        <i class="fa fa-clock-o"></i>
                                    </div>
                                </div>
                                <!-- /.input group -->
                            </div>
                            <!-- /.form group -->
                        </div>
                    </div>
                </div>
            </div>

        </form>
    </div>
    <!-- /.box-body -->
    <div class="box-footer">
        <button id="save" type="button" class="btn btn-info" style="width:120px;">保存</button>
        <button id="cancel" type="button" class="btn btn-default pull-right" style="width:90px;">取消</button>
    </div>
    <div class="overlay hidden">
        <i class="fa fa-refresh fa-spin"></i>
    </div>
</div>
<script type="text/javascript">
//模块名称定义
var moduleName = 'gameType';

//取消
$('#cancel').on('click', function() {
    window.location.href = 'admin#' + moduleName;
});

function del_profit(o) {
    $(o).parent().parent().parent().fadeOut(function () {
        this.remove();
    });
}
function add_profit(o) {
    var html = '<div class="form-group list_profit" style="overflow:hidden;">';
    html += '<div style="width:100%"><label>触摸点位 - 收益率（%）</label><span> - <a href="javascript:void(0)" onclick="del_profit(this)">[删除]</a></span></div>'
    html += '<div style="float:left;display:block;width:49%">'
    html += '<input type="text" name="contact" value="1" class="form-control" placeholder="触摸点位">'
    html += '</div>'
    html += '<div style="float:left;width:2%;display:block;text-align:center;">-</div>'
    html += '<div style="float:left;display:block;width:49%">'
    html += '<input type="text" name="profit_rate" value="100" class="form-control" placeholder="收益比例">'
    html += '</div>'
    html += '</div>';
    $(o).parent().before(html);
}

$(".timepicker").timepicker({
    showInputs: false,
    minuteStep: 1,
    showMeridian: false,
    disableFocus: false,
    defaultTime: false
});

$('#save').on('click', function() {
    var mon = 2;
    if ( $("#mon").is(':checked')) mon = 1;
    var tue = 2;
    if ( $("#tue").is(':checked')) tue = 1;
    var wed = 2;
    if ( $("#wed").is(':checked')) wed = 1;
    var thu = 2;
    if ( $("#thu").is(':checked')) thu = 1;
    var fri = 2;
    if ( $("#fri").is(':checked')) fri = 1;
    var sat = 2;
    if ( $("#sat").is(':checked')) sat = 1;
    var sun = 2;
    if ( $("#sun").is(':checked')) sun = 1;

    var profit_rate_list = [];
    $(".list_profit").each(function () {
        var o = Object();
        o.contact = $(this).find("input[name=contact]").val();
        o.profit_rate = $(this).find("input[name=profit_rate]").val();
        profit_rate_list.push(o);
    });

    if (profit_rate_list.length <= 0) {
        layer.alert("请先配置触摸点位");
        return;
    }
    showLoad();
    $.ajax({
        type : "post",
        url : 'admin/' + moduleName + '/addoreditdata',
        dataType:"json",
        data: {
            id : $('#id').val()
            ,game_name : $('#game_name').val()
            ,show_name : $('#show_name').val()
            ,name_code : $('#name_code').val()
            ,norms : $('#norms').val()
            ,value_length : $('#value_length').val()
            ,mon : mon
            ,tue : tue
            ,wed : wed
            ,thu : thu
            ,fri : fri
            ,sat : sat
            ,sun : sun
            ,profit_rate_list:profit_rate_list
            ,open_time : $('#open_time').val()
            ,close_time : $('#close_time').val()
            ,close_time_type : $('#close_time_type').val()
            ,exchange_rate : $('#exchange_rate').val()
            ,multiplying_power : $('#multiplying_power').val()
        },
        success : function(msg) {
            //layer.msg(msg.msg);
            if (msg.code == 0)
                $.scojs_message(msg.msg, $.scojs_message.TYPE_OK);
            else
                $.scojs_message(msg.msg, $.scojs_message.TYPE_ERROR);
            hideLoad();
        }
    });
});
</script>